#ifndef DATA_MANAGER_H
#define DATA_MANAGER_H

#include "../fileio/FileManager.h"
#include "Data.h"
#include "../const/const.h"
#include "../indexmanager/IndexManager.h"
#include "../bufmanager/BufPageManager.h"
#include "../utils/pagedef.h"
#include <string>
#include <vector>
#include <cstring>
#include <utility>

class DataManager{
	FileManager* fm;
	BufPageManager* bpm;
	int fileID;
public:
	DataManager(FileManager* _fm, BufPageManager* _bpm){
		fm = _fm;
		bpm = _bpm;
	}
	~DataManager() {}
public:
	BufPageManager* getBpm() {return bpm;}
	void setFileID(int _fileID) {fileID = _fileID;}
	int getFileID() {return fileID;}
	void initDatabase();
	int insertData(Data &data, std::string table);
	void addIndex(std::string table, int column);
	void removeIndex(std::string table, int column);
	void searchData(vector<search_condition> &condition, std::string table, search_result& searchResult);
	void deleteData(vector<search_condition> &condition, std::string table);
	void updateData(vector<search_condition> &condition, std::string table, vector<replace_pair>& newPair);
	void getTableInfo(std::string table, Data& data, int& table_page, int& has_index);
	bool judgeCondition(std::vector<std::string>& singleData, search_condition& condition, int& nullInf);
};

#endif // DATA_MANAGER_H
